package algorithm.dynamic_programming;

import java.util.Stack;

public class ReverseStackUsingRecursive {

    //利用递归栈保存数据信息
    public static void reverse(Stack<Integer> stack){
        if(stack.isEmpty()){
            return;
        }
        int f = f(stack);
        reverse(stack);
        stack.push(f);
    }

    public static int f(Stack<Integer> stack){
        int a = stack.pop();
        if(stack.isEmpty()){
            return a;
        }
        int f = f(stack);
        stack.push(a);
        return f;
    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(3);
        stack.push(2);
        stack.push(1);
        System.out.println(stack);
        reverse(stack);
        System.out.println(stack);
    }
}
